<?php
/**
 * Created by PhpStorm.
 * User: zhanghua
 * Date: 18-9-23
 * Time: 下午5:39
 */

namespace app\common\service;


use think\Exception;

class BaseService
{

    protected static $_instance = [];


    final private function __construct()
    {
        $this->init();
    }

    public function init(){

    }


    public static function getInstance($class)
    {
        if(isset(self::$_instance[$class])){
            return self::$_instance[$class];
        }

        self::$_instance[$class] = new static();

        return self::$_instance[$class];
    }


    public static function __callStatic($method, $arguments)
    {

        $service = self::getInstance(static::class);

        if (method_exists($service, $method)) {
            return call_user_func_array([$service, $method], $arguments);
        } else {
            throw new \RuntimeException( 'The method ' . $method . ' of the class ' . get_class($service) . '  not found');
        }
    }



}